<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <link rel="shortcut icon" href="../images/favicon.ico">
    <link rel="apple-touch-icon-precomposed" href="../images/apple-touch-icon.png">
    <title>timepart</title>
    <link rel="stylesheet" href="../scripts/lib/seedsui/seedsui.min.css">
</head>

<body ontouchstart="">
<section>
	<header>
        <div class="titlebar">
            <a class="titlebar-button" href="javascript:back()">
                <i class="icon icon-arrowleft"></i>
            </a>
            <h1 class="titlebar-title">时间段控件</h1>
        </div>
    </header>
	<article>
        <div class="timepart group" id="ID-Timepart"></div>
        <a class="radius4 button block" style="margin:8px" id="ID-BtnSubmit">预约</a>
	</article>
</section>
    <script src="../scripts/lib/seedsui/seedsui.min.js"></script>
	<script>
        var view={
            /*=========================
              Model
              ===========================*/
            render:function(){
                var self = this;
                //提示框
                this.toast=new Toast("");
                //时间段
                this.part1,this.part2;
                this.timepart=new Timepart("#ID-Timepart",{
                    startTime:"7:00",
                    endTime:"22:00",
                    
                    onConflictOver:function(e){
                        if(e.target.status=="active"){
                            self.toast.setText("不能跨选禁用时间段");
                            self.toast.show();
                            //移除所有选中效果
                            e.removeAllActive();
                        }
                    },
                    onConflictContain:function(e){
                        if(e.target.status=="disabled"){
                            self.toast.setText("时间段冲突");
                            self.toast.show();
                        }
                    },
                    onClickActive:function(e){
                        console.log(e.target);
                        e.removeAllActive();
                    },
                    onClickDisabled:function(e){
                        var data=JSON.parse(e.target.getAttribute("data-progress"));
                        self.toast.setText("开始时间:"+data.startTime+",结束时间:"+data.endTime);
                        self.toast.show();
                    },
                    onClickValid:function(s){//点击有效区域
                        if(s.clickCount==1){//如果点击了一次
                            self.part1=s.target;
                            self.part1.classList.add(s.params.activeClass);
                        }else if(s.clickCount==2){//如果点击了两次
                            self.part2=s.target;
                            //选中
                            var times=s.getTimesByParts(self.part1,self.part2);
                            s.activeTimes(times.startTime,times.endTime);
                        }else if(s.clickCount==3){//如果点击了三次
                            s.removeAllActive();
                        }
                    },
                });
                var data=JSON.stringify({startTime:"3:00",endTime:"5:00"});
                //this.timepart.disableTimes(null,"17:50",["SID-DisabledInfo"],data);
                this.timepart.disableTimes(null,new Date().setMinuteCeil(10),["SID-DisabledBefore"],data);
                //加载数据
                this.loadData();
            },
            refresh:function(){
                console.log("刷新");
            },
            destroy:function(){
                console.log("移除");
            },
            loadData:function(){

                this._attach();//使用backbone时，此行无用
            },
            /*=========================
              Events
              ===========================*/
            _attach:function(e){
                var self=this;
                document.getElementById("ID-BtnSubmit").addEventListener("click",function(e){
                    var times=self.timepart.getActiveTimes();
                    var starttime=times.startTime;
                    var endtime=times.endTime;
                    console.log("选中时间："+starttime+" ~ "+endtime);
                },false);
            },
            /*=========================
              Event Handler
              ===========================*/
        }

        window.addEventListener("load",function(){
            view.render();
        }, false);

		//定义exmobi返回
		function back() {
			history.go(-1);
		}
	</script>
</body>
</html>